package cn.myjerry.net.tcp.socket;

import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 1、建立服务器
 * 2、接受客户端链接 --> 阻塞式
 * 3、发送数据 + 接受数据
 * @author Jerry
 *
 */
public class Server {
	public static void main(String[] args) throws IOException {
		ServerSocket server = new ServerSocket(8888);
		Socket socket = server.accept();
		System.out.println("一个客户端建立链接");
		
		String str = "欢迎您使用本系统";
		/*
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
		
		bw.write(str);
		bw.newLine();
		bw.flush();
		*/
		
		DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
		dos.writeUTF(str);
		dos.flush();
		
	}
}
